-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds null migrator #31
feat: adds null migrator #31
Conversation
acef7e6
to
69a2377
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Just a few nits.
if models.len() != 1 { | ||
return Err(NullMigratorError::TooManyModelVersions); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if models.len() != 1 { | |
return Err(NullMigratorError::TooManyModelVersions); | |
} | |
snafu::ensure!(models.len() == 1, NullMigratorError::TooManyModelVersionsSnafu); |
define_model!(NullModelB, "v2"); | ||
#[test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would separate these with some whitespace as a readability thing.
use serde::{Deserialize, Serialize}; | ||
|
||
use super::common::define_model; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend not to separate use
statements with whitespace, and let rustfmt
handle ordering.
The exception to this is pub use
statements for shaping the interface.
We'll want to increment the version and tag the repo appropriately so that we can pull this change into Bottlerocket. Here's the commit where that was done in the last version bump. |
69a2377
to
37ecfd5
Compare
New version should be |
66c4a65
to
4915376
Compare
Yes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 🚀
#[snafu(visibility(pub))] | ||
pub enum NullMigratorError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbgbt We should strongly consider not using Snafu for pub errors. The long-and-short of it is that we are exposing a library and its traits in our public interface and it might be impossible to avoid a major version break if the Snafu library changes in some way. Can discuss.
For this PR it's fine, but I would recommend a backlog item to convert away from pub Snafu errors in favor of hand-rolled errors (they're simple, it's not a lot of boilerplate).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. I've cut #32 to track this idea.
@@ -0,0 +1,201 @@ | |||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of these filenames, I would go with
bottlerocket-settings-sdk/tests/migration_validation/linear.rs
bottlerocket-settings-sdk/tests/migration_validation/null.rs
assert!(matches!( | ||
NullMigratorExtensionBuilder::with_name("null-migrator") | ||
.with_models(vec![BottlerocketSetting::<NullModelA>::model()]) | ||
.build(), | ||
Ok(_) | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or
assert!(matches!( | |
NullMigratorExtensionBuilder::with_name("null-migrator") | |
.with_models(vec![BottlerocketSetting::<NullModelA>::model()]) | |
.build(), | |
Ok(_) | |
)); | |
assert!( | |
NullMigratorExtensionBuilder::with_name("null-migrator") | |
.with_models(vec![BottlerocketSetting::<NullModelA>::model()]) | |
.build() | |
.is_ok() | |
); |
Or (this is probably best because the Error is shown in the panic text)
NullMigratorExtensionBuilder::with_name("null-migrator")
.with_models(vec![BottlerocketSetting::<NullModelA>::model()])
.build()
.unwrap();
|
||
#[test] | ||
fn test_multiple_models() { | ||
assert!(matches!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, can use is_err()
Signed-off-by: Sam Berning <[email protected]>
Signed-off-by: Sam Berning <[email protected]>
63df59d
to
09be241
Compare
Issue #, if available: #30
Description of changes:
Adds a
NullMigrator
that can be used with settings with only one version. This removes some of the boilerplate when developing a new extension.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.